#pragma once
#include <Windows.h>
#include <memory>
#include <string>
#include "TypeDef.h"
#include "BaiduLrcParser.h"
#include "BaiduPageParser.h"
#include "SimpleWebPageParser.h"
#include "SimpleFileDownloader.h"
 
extern HMODULE Gbl_ModuleHandler;

class CBitmapHelper
{
public:
     CBitmapHelper(unsigned int resId)
     {
         m_BitPic = LoadBitmap(Gbl_ModuleHandler, MAKEINTRESOURCE(resId));
     }
     ~CBitmapHelper()
     {
         if( m_BitPic )
             DeleteObject(m_BitPic);
     }
     HBITMAP GetHandler() const
     {
         return m_BitPic;
     }
private: 
     HBITMAP m_BitPic;
};


class IFileDownloader;
class IWebPageParse;

class CBaiduMusicImp
{
public:
     CBaiduMusicImp();
     int SearchSong(const tstring & SongName, tstring & ErrMsg, SongList & List, int Page=0);
     int SearchLrc(const tstring & Song, const tstring & Singer, tstring & ErrMsg, LrcList & List, int Page=0);
     bool GetMp3DownloadUrl(int Idx, tstring & Url);
     bool GetLrcDownloadUrl(int Idx, tstring & Url);
     int GetLrcTotalNum()const;
     int GetSongTotalNum()const;
     const TCHAR * GetEngineName()const;
     bool GetEngineLogo(HBITMAP & Logo)const;
private:
     static const int m_SongNumPerPage;
     static const TCHAR * m_EngineName;

     tstring m_SongName;                          // Song name
     CBitmapHelper  m_EngineLogo;                 // Engine logo
     CBaiduSongParser    m_SongParser;            // Parser for getting music file download url
     CBaiduLrcParser     m_LrcParser;             // Parser for getting lrc file download url
     CBaiduSongNumParser m_SongNumParser;         // Get song total searching result count
     CBaiduLrcNumParser  m_LrcNumParser;          // Get lrc total searching result count

     std::auto_ptr<IFileDownloader>  m_Downloader;
     std::auto_ptr<IWebPageParse>    m_MusicWebPageParse;
};
